package cn.net.ait.hr.service;

import org.guiceside.persistence.Transactional;
import org.guiceside.persistence.TransactionType;
import org.guiceside.persistence.entity.IdEntity;
import org.guiceside.persistence.hibernate.dao.hquery.*;
import org.guiceside.persistence.hibernate.dao.enums.ReturnType;
import org.guiceside.persistence.hibernate.dao.annotation.EQ;
import org.guiceside.commons.Page;
import cn.net.ait.hr.entity.HrDuty;
import cn.net.ait.hr.entity.HrOrganization;
import cn.net.ait.hr.entity.HrEmployee;
import com.google.inject.Singleton;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: zhenjia
 * Date: 2009-3-30
 * Time: 11:30:24
 * To change this template use File | Settings | File Templates.
 */
@Singleton
public class HrDutyService extends HQuery {

    @Transactional(type = TransactionType.READ_WRITE)
    public HrDuty getDuty(Long id) {

//        Page<HrDuty> dutyPage=$($eq("useYn","N")).page(HrDuty.class,0,5);
//        List<HrDuty> dutyList=dutyPage.getResultList();
//        $(dutyList).each(new EachAdapter() {
//            @Override
//            public void invoke(Object o) {
//                HrDuty hrDuty= (HrDuty) o;
//                System.out.println(hrDuty.getDutyNameZh());
//                System.out.println(hrDuty.getUseYn());
//            }
//        });
        $($order("id",false),$eq("dutyId.useYn","Y"),$alias("dutyId","dutyId")).each(HrEmployee.class,new EachAdapter() {
            @Override
            public void invoke(Object o) {
                HrEmployee hrEmployee= (HrEmployee) o;
                System.out.println(hrEmployee.getEmpNameZh());
                //To change body of implemented methods use File | Settings | File Templates.
            }
        } );
        int i=$($count("id")).returnType(ReturnType.PLAIN).value(HrDuty.class,Integer.class);
        System.out.println(i);
        //$($order("id")).list(HrDuty.class);
//        $().attr(HrDuty.class,"useYn","Y").each(new EachAdapter() {
//            @Override
//            public void invoke(Object o) {
//                HrDuty hrDuty= (HrDuty) o;
//                System.out.println(hrDuty.getDutyNameZh());
//                System.out.println(hrDuty.getUseYn());
//            }
//        }).save();
//        List<String> useYnList= (List<String>) $("useYn = N").attr(HrDuty.class,"useYn");
//        if(useYnList!=null&&!useYnList.isEmpty()){
//            for(String useYn:useYnList){
//                System.out.println(useYn);
//            }
//        }
//        $(id).save(HrDuty.class, new BeforeCallback() {
//            @Override
//            public void invoke() {
//                HrDuty hrDuty=this.get(HrDuty.class);
//                hrDuty.setUseYn("Y");
//
//            }
//        });
        HrDuty hrDuty = null;
        return hrDuty;
    }
}
